package com.example.redis.pubsub;

import com.example.redis.JredisUtils;
import redis.clients.jedis.Jedis;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Robin-Li on 2017/6/6.
 */
public class RedisBlockQueue {
    public static void main(String[] args) {
        Jedis jedis = JredisUtils.getInstance();

        System.out.println( new Date());
        push(jedis,"11","a");
        push(jedis,"11","b");
        push(jedis,"11","c");
        push(jedis,"11","d");
        System.out.println(jedis.lrange("11",0,-1));
        System.out.println(jedis.brpop(0,"11"));
        System.out.println( new Date());
        jedis.close();
    }

    public  static void push(Jedis jedis,String key,String value)  {
        jedis.ltrim(key,0,2);
        jedis.lpush(key,value);

        /*if(jedis.llen(key) >=3){
            try {
                Thread.sleep(9000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }else{
            jedis.lpush(key,value);
        }*/

    }
}
